package com.ww.java8.fp.lambda;

/**
 * TODO
 *
 * @author wanggw
 * @date 2022-11-18 00:16:31
 */
public class FunctionalAnnotation {
    public String goodbye(String arg) {
        return "Goodbye, " + arg;
    }

    public static void main(String[] args) {
        FunctionalAnnotation fa = new FunctionalAnnotation();
        Functional f = fa::goodbye;
        FunctionalNoAnn fna = fa::goodbye;
        /**
         * 虽然FunctionalAnnotation确实符合Functional模型，但是Java不允许我们像fac定义的那样，将FunctionalAnnotation直接赋值给Functional，
         * 因为FunctionalAnnotation并没有显式地去实现Functional接口。
         * Java 8 运行我们将函数赋值给接口，这样语法更简单漂亮
         */
//        Functional fac = fa;
        Functional f1 = a -> "Goodbye, " + a;
        FunctionalNoAnn fnal = a -> "Goodbye, " + a;
    }
}

@FunctionalInterface
interface Functional {
    String goodbye(String arg);
}

interface FunctionalNoAnn {
    String goodbye(String arg);
}